{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6a5d7341",
   "metadata": {},
   "source": [
    "# CPW Kappa Calculation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5955a435",
   "metadata": {},
   "source": [
    "Let's start by importing Qiskit Metal: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e4d8800d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict, open_docs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32ed101f",
   "metadata": {},
   "source": [
    "Next, let's import the function \"kappa_in\" located in the file kappa_calculation.py. This function calculates the photon loss of a CPW resonator which is capacitively coupled to an input transmission line. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d8157536",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the function \"kappa_in\" from the file kappa_calculation.py \n",
    "from qiskit_metal.analyses.em.kappa_calculation import kappa_in"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccb6c5ee",
   "metadata": {},
   "source": [
    "The function \"kappa_in\" takes either three or six arguments, depending on how the lowest resonant frequency of the resonator is handled. In the first case, the resonant frequency of the CPW resonator is calculated numerically (using HFSS, for example) and passed as a floating-point input along with the frequency of interest and the capacitance between the resonator and the transmission line. In the second case, the lowest resonant frequency of the CPW resonator can be estimated by assuming an ideal resonator, in which case some additional inputs are required (1/2 or 1/4 depending on the type of resonator, the resonator length, width of resonator trace, width of resonator gap.)\n",
    "\n",
    "Here's a quick sanity check to verify that we only get numerical output from this function in the cases of N=3 or N=6 arguments:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "407a7792",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output for N=1 Args: None\n",
      "Output for N=2 Args: None\n",
      "Output for N=3 Args: 1591.5494309189535\n",
      "Output for N=4 Args: None\n",
      "Output for N=5 Args: None\n",
      "Output for N=6 Args: 3234.721973158391\n",
      "Output for N=7 Args: None\n"
     ]
    }
   ],
   "source": [
    "# SANITY CHECK #1 \n",
    "# Let's check that output is only given for three and six arguments  \n",
    "print(\"Output for N=1 Args:\", kappa_in(1.0))\n",
    "print(\"Output for N=2 Args:\", kappa_in(1.0, 1.0))\n",
    "print(\"Output for N=3 Args:\", kappa_in(1.0, 1.0, 1.0))\n",
    "print(\"Output for N=4 Args:\", kappa_in(1.0, 1.0, 1.0, 1.0))\n",
    "print(\"Output for N=5 Args:\", kappa_in(1.0, 1.0, 1.0, 1.0, 1.0))\n",
    "print(\"Output for N=6 Args:\", kappa_in(1.0, 1.0, 1.0, 1.0, 1.0, 1.0))\n",
    "print(\"Output for N=7 Args:\", kappa_in(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0ca357e",
   "metadata": {},
   "source": [
    "Now, let's actually calculate the photon loss for a representative CPW resonator with realistic values of input parameters. Here we'll assume a resonant frequency of 5 GHz, capacitive coupling of 30fF and a CPW resonant frequency of 4 GHz. The calculated value of kappa is the range of 0-1 MHz, as expected. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "98b22c3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculated kappa (in Hz): 161144.37988054403 Hz\n",
      "Calculated kappa (in MHz): 0.16114437988054403 MHz\n"
     ]
    }
   ],
   "source": [
    "# SANITY CHECK #2\n",
    "# Let's check that the magnitude of the output is what we would expect for 3 arguments:\n",
    "# Input #1: omega = 5GHz = 5E9 Hertz \n",
    "# Input #2: C_in = 30fF = 30E-15 Farads \n",
    "# Input #3: omega_n = 4GHz = 4.5E9 Hertz \n",
    "print(\"Calculated kappa (in Hz):\", kappa_in(5.0E9, 30.0E-15, 4.5E9), \"Hz\")\n",
    "print(\"Calculated kappa (in MHz):\", kappa_in(5.0E9, 30.0E-15, 4.5E9)/1.0E6, \"MHz\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
